package me.cxlr.qinlauncher2.view.settings;

import android.os.Bundle;

import androidx.navigation.fragment.NavHostFragment;
import androidx.preference.DropDownPreference;
import androidx.preference.PreferenceFragmentCompat;

import me.cxlr.qinlauncher2.R;
import me.cxlr.qinlauncher2.dao.AppDao;
import me.cxlr.qinlauncher2.util.ThemeUtil;

/**
 * @author 酷安用户:山轮纸
 */
public class DrawerSettingsFragment extends PreferenceFragmentCompat {
    private AppDao appDao;

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.preferences_drawer_settings, rootKey);

        appDao = new AppDao();

        // 查看隐藏的应用
        DropDownPreference appDrawerHide = findPreference("app_drawer_hide");
        assert appDrawerHide != null;
        appDrawerHide.setOnPreferenceClickListener(preference -> {
            NavHostFragment.findNavController(DrawerSettingsFragment.this).navigate(R.id.action_drawerSettingsFragment_to_showHiddenAppSettingsFragment);
            return true;
        });

        // 手动修复--以后移动到开发者模式里
        DropDownPreference shouDongXiuFu = findPreference("shou_dong_xiu_fu");
        assert shouDongXiuFu != null;
        shouDongXiuFu.setOnPreferenceClickListener(preference -> {
            // dialogShouDongXiuFu();
            return true;
        });
        shouDongXiuFu.setVisible(false);
    }

    @Override
    public void onResume() {
        super.onResume();
        ThemeUtil.initTheme();
    }

    private void dialogShouDongXiuFu() {
        // AlertDialog alertDialog = new AlertDialog.Builder(requireContext())
        //         .setTitle("手动修复")
        //         .setMessage("用于修复升级应用后应用抽屉内图标重复的问题，同时文件夹会被删除和隐藏的应用也会回到应用抽屉")
        //         .setPositiveButton("是", (dialog, which) -> {
        //             AppDao appDao = new AppDao();
        //             appDao.deleteAllApp();
        //             List<App> appList = SoftwareManager.getInstance().getAppList();
        //             appDao.saveApp(appList);
        //         })
        //         .setNegativeButton("关闭", (dialog, which) -> dialog.dismiss())
        //         .create();
        // alertDialog.show();
    }
}